package Thread;
class MyThread3 implements Runnable{//不仅仅可以搭配线程执行

    @Override
    public void run() {
    while(true){
        System.out.println("hello runnable");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    }
}
public class ThreadDemo3 {
    public static void main(String[] args) {
        //这种写法相当于把线程和要执行的任务解耦合了
    //Runnable runnable = new MyThread3();//只是一段可执行的的代码
    //Thread t = new Thread(runnable);
        Thread t = new Thread(new MyThread3());
        t.start();
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
